<?php

namespace App\Providers;

use App\Events\BlogView;
use App\Models\Post;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\BlogView' => [
            'App\Listeners\BlogViewListener',
        ]
    ];

    protected $subscribe = [
        \App\Listeners\SomeSubscriber::class
    ];


    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

//        $events->listen('event.name', function ($foo, $bar) {
//            //
//        });

//        \Event::listen($event, $listener)

//        Event::listen('auth.login', function($event)
//        {
//            Auth::user()->last_login = new DateTime;
//            Auth::user()->last_login_ip = Request::getClientIp();
//            Auth::user()->save();
//        });


//        \Event::listen(BlogView::class,function($event){
//            /**
//             * @var $post Post
//             */
//            $post =$event->post;
//            if ($post){
//                $post->view_count=$post->view_count+1;
//                $post->save();
//            }
//        });
    }
}
